﻿using System.Collections;
using System.Collections.Generic;
using GameFramework.Battle.Core;
using Gameplay.PVE.Entity;
using UnityEngine;

namespace Gameplay.PVE
{
    public class IsAttackInRange : Havior
    {
        
        private BattleUnit unit;

        public override ETaskResult Execute(ETaskResult result,bool last)
        {
            if (unit.Data.IsAttackInRange() && unit.Data.IsInScreen())
            {
                PveManager.Instance.isEnemyStartSearch = true;
                /*if (unit.Data.isManualMoving && unit.Data.manualForward.sqrMagnitude >= 0.01f)
                {
                    
                }
                else*/
                /*if (PveManager.Instance.isInPve || (!unit.Data.hasJoinBattle && PveManager.Instance.CheckIsInBattleArea(unit.Data.team,unit.Data.position)))
                {
                    unit.Data.hasJoinBattle = true;
                }*/
                //if (unit.Data.hasJoinBattle)
                {
                    /*if (!unit.Data.IsInAttack() && !unit.Data.IsInSkill() && unit.Data.IsCanAttack() && !unit.Data.isReloading)
                    {
                        unit.Transmit(ETransmitType.BeforeAttack);
                    }*/
                    unit.Transmit(ETransmitType.Attack);
                    return ETaskResult.Failed;
                }
                /*else
                {
                    return ETaskResult.Successed;
                }*/
            }
            else
            {
                return ETaskResult.Successed;
            }
        }

        public override void Parse(Dictionary<string, object> data)
        {
            
        }

        public override void SharedVariableChanged(string key, object value)
        {
            if (key == ESharedVariablesType.Executor)
            {
                unit = (BattleUnit) value;
            }
        }
    }

}
